package com.entity;

import com.util.LocalInformation;

import java.util.ArrayList;
import java.util.Date;

import static com.util.LocalInformation.getNowDate;

/**
 * Created by wlc on 2018/5/5.
 */
public class Message {
    /**
     * 静态属性
     */
    private String id;   //无需自己设置
    private String senderId;
    private String senderName;
    private String receiverId;
    private String receiverName;
    private String date;
    private String type;
    private String title;
    private String content;

    /**
     * 消息状态(无需自己设置)
     */
    private String readStatus; //1为读，0为未读

    public Message(){
        this.id = LocalInformation.getTimeID();
        this.senderId = "null";
        this.senderName = "null";
        this.receiverId = "null";
        this.receiverName = "null";
        this.date = "null";
        this.type = "null";
        this.content = "null";
        this.readStatus = "null";
    }

    /**
     *数据成员设置和获取函数
     */
    public void setId(String id){
        this.id = id;
    }

    public String getId(){
        return this.id;
    }

    public void setSenderId(String senderId){
        this.senderId = senderId;
    }

    public String getSenderId(){
        return this.senderId;
    }

    public void setSenderName(String senderName){
        this.senderName = senderName;
    }

    public String getSenderName(){
        return this.senderName;
    }

    public void setReceiverId(String receiverId){
        this.receiverId = receiverId;
    }

    public String getReceiverId(){
        return this.receiverId;
    }

    public void setReceiverName(String receiverName){
        this.receiverName = receiverName;
    }

    public String getReceiverName(){
        return this.receiverName;
    }

    public void setDate(String date){
        this.date = date;
    }

    public String getDate(){
        return this.date;
    }

    public void  setType(String type){
        this.type = type;
    }

    public String getType(){
        return this.type;
    }

    public void setTitle(String title){
        this.title = title;
    }

    public String getTitle(){
        return this.title;
    }

    public void setContent(String content){
        this.content = content;
    }

    public String getContent(){
        return this.content;
    }

    public void setReadStatus(String readStatus){
        this.readStatus = readStatus;
    }

    public String getReadStatus(){
        return this.readStatus;
    }

    /**
     * 封装数据权限申请
     * @param senderId
     * @param senderName
     * @param authorityTitle
     * @param authorityApplicationStatus
     */
    public void dataAuthorityApplication(String senderId, String senderName, String authorityTitle, String authorityApplicationStatus){
        this.receiverId = "0";
        this.receiverName = "root";
        this.senderId = senderId;
        this.senderName = senderName;
        int[] nowdate = getNowDate(new Date());
        this.date = nowdate[0] + "-" + nowdate[1] + "-" + nowdate[2];
        this.type = "数据权限";
        this.title = "权限申请";
        this.content = authorityTitle + ":";
        int index = 1;
        for (int i = 0; i < authorityApplicationStatus.split("").length;i++){
            if (authorityApplicationStatus.split("")[i].equals("1")){
                switch (i){
                    case 0: this.content += index + ".数据查找；";index++;break;
                    case 1: this.content += index + ".数据导入；";index++;break;
                    case 2: this.content += index + ".数据修改；";index++;break;
                    case 3: this.content += index + ".数据删除；";index++;break;
                }
            }
        }
    }

    /**
     * 封装意见反馈消息
     * @param senderId
     * @param senderName
     */
    public void FeedBackMessage(String senderId, String senderName){
        this.receiverId = "0";
        this.receiverName = "root";
        this.senderId = senderId;
        this.senderName = senderName;
        int[] nowdate = getNowDate(new Date());
        this.date = nowdate[0] + "-" + nowdate[1] + "-" + nowdate[2];
        this.type = "意见反馈";
    }

    /**
     * 封装消息回复消息
     */
    public void replyMessage(){
        this.senderId = "0";
        this.senderName = "root";
        int[] nowdate = getNowDate(new Date());
        this.date = nowdate[0] + "-" + nowdate[1] + "-" + nowdate[2];
        this.type = "消息反馈";
    }

    /**
     * 将消息转换成列表
     * @return
     */
    public ArrayList<String> messageToList(){
        return new ArrayList<String>(){{
            add(id);
            add(receiverId);
            add(receiverName);
            add(senderId);
            add(senderName);
            add(type);
            add(date);
            add(title);
            add(content);
            add(readStatus);
        }};
    }

    /**
     * 将列表转换成消息
     * @param messageList
     */
    public void listToMessage(ArrayList<String> messageList){
        this.id = messageList.get(0);
        this.receiverId = messageList.get(1);
        this.receiverName = messageList.get(2);
        this.senderId = messageList.get(3);
        this.senderName = messageList.get(4);
        this.type = messageList.get(5);
        this.date = messageList.get(6);
        this.title = messageList.get(7);
        this.content = messageList.get(8);
        this.readStatus = messageList.get(9);
    }
}
